<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.ignou.mca.beans.UserVO"%>
<%@page import="com.ignou.mca.datasource.DatabaseOperations"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.ignou.mca.beans.SubjectBean"%>
<%@page import="java.util.Iterator"%><html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="theme/style.css"
	media="screen" />
<title>OES - Displaying subjects</title>
	<script type='text/javascript'>
	function deleteSubjectConfirm(subId, subName)
	{
		var altTxt = "You are trying to delete "+subName+" subject.\n Click 'OK' to continue to delete. \n Click 'Cancel' to cancel the submission. '";
		if (confirm(altTxt))
		{
			window.location.href = 'DeleteSubject.jsp?subject='+subId; 
		}
		else
		{
		}
	}
	
	function getExamList(subId)
	{
		window.location.href = 'Exams.jsp?subject='+subId; 
	}
	
	function addExam(subId)
	{
		window.location.href = 'AddExam.jsp?subject='+subId; 
	}

	function getQuestionList(subId)
	{
		window.location.href = 'Questions.jsp?subject='+subId;
	}
	</script>
</head>
<body>
	<div id="MainWrapper">
		<jsp:include page="header.jsp" /> 
		<jsp:include page="LeftContainer.jsp" />
		<div id="MainContent">
		<center>
			<h1><u>Subjects available</u></h1>
			<%
				UserVO uvo = (UserVO) session.getAttribute("UserVO");
				if(uvo==null)
				{
					response.sendRedirect("./Login.jsp");
				}
				else
				{
					DatabaseOperations dbOperations = new DatabaseOperations();
					ArrayList<SubjectBean> allSubs = dbOperations.getAllSubjects();
					session.setAttribute("Subjects", allSubs);
				%>
				<table align="center" width="100%" height="100%">	
				<%	
					Iterator<SubjectBean> itr = allSubs.iterator(); 
					while(itr.hasNext()) 
					{
						SubjectBean sb = (SubjectBean)itr.next();	
					%>
					<tr>
						<td><%= sb.getSubjectName() %></td>
						<td>  <a href="UpdateSubject.jsp?subject=<%=sb.getSubjectId()%>">Update Subject</a></td>
						<td>  <a href="javascript: getQuestionList(<%=sb.getSubjectId() %>)">Questions</a></td>
						<td>  <a href="javascript: getExamList(<%=sb.getSubjectId() %>)">List Exams</a></td>
						<td>  <a href="javascript: addExam(<%=sb.getSubjectId() %>)">Add Exam</a></td>
						<td>  <a href="javascript: deleteSubjectConfirm(<%=sb.getSubjectId() %>,'<%=sb.getSubjectName() %>');">Delete Subject</a></td>
					</tr>
					<%
					}
					%>
					</table>
					<br><br><br>
					Click <a href="AddSubject.jsp">here</a> to add Subjects.<br>
					<%
				}
			%>
		</center>
		</div>
		<jsp:include page="footer.jsp" />
	</div>
</body>
</html>